const sm2 = require('sm-crypto').sm2;

const publicKeyHex = "042929C3E7DBAD2884080E2ED06FA2CA68501D0C38F664EFD21B9CF3FE064783D795CA8D1F9712305A013A1FD261B37F9B02BCA43D01777B83BA23478BF21F29D4";
const privateKeyHex = "2A0F962B1D6A412D093525B4855A35B76F7BA5F446494A82CC59648F898A3A6F";

function encrypt(plaintext) {
  const cipherMode = 1; // 1 - C1C3C2，0 - C1C2C3，默认为1
  return sm2.doEncrypt(plaintext, publicKeyHex, cipherMode);
}

function decrypt(ciphertext) {
  return sm2.doDecrypt(ciphertext, privateKeyHex);
}

module.exports = {
  encrypt,
  decrypt
};
